<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用 constructor 属性来查看对象是否为日期 (包含字符串 "Date")</title>
</head>

<!-- constructor 属性返回所有 JavaScript 变量的构造函数。 -->

<body>
    <p>判断是否为日期。</p>
    <p id="demo"></p>
    <script>
        var myDate = new Date();
        document.getElementById("demo").innerHTML = isDate(myDate);
        function isDate(myDate) {
            return myDate.constructor.toString().indexOf("Date") > -1;
        }
    </script>
</body>

</html>